
{extend name='public/base' /}
{block name="css"}

{/block}
{block name="content"}
<div class="ibox xiaoshi">
    <div class="ibox-content">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form class="form-inline" id="user-form">
                    <div class="select-list">
                        <ul>
                            {:li_time()}

                            {:li_search()}
                        </ul>
                    </div>
                </form>
            </div>


        </div>

    </div>
</div>



<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-content">
                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-danger btn-rounded multiple " onclick="del_all()">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-warning btn-rounded" onclick="$.table.exportExcel()">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <div class="table-striped">
                    <table id="bootstrap-table"  ></table>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"} <!--js处理区-->

<script>
   layui.use(['element','jquery','laydate'], function () {
        var element = layui.element;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        //日期范围
        laydate.render({
            elem: '#time'
            ,type: 'month'
        });
    });

    $(function() {
        var options = {
            url: "{:url('index')}",
            deleteUrl:  "{:url('del')}?id={id}", //删除链接
            exportUrl:  "{:url('export')}",  //导出
            updateUrl: "", //编辑
            addUrl:    "", //添加
            detailUrl:  "",    //详细
            sortName: "id",
            sortOrder: "asc",
            modalName: "日志",
            pageSize: 20,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID'
                },

                {
                    field: 'title',
                    title: '请求者'
                },
                {
                    field: 'method',
                    title: '方式'
                },
                {
                    field: 'url',
                    title: '地址'
                },
                {
                    field: 'ip',
                    title: 'IP'
                },
                {
                    field: 'os',
                    title: '操作系统'
                },
                {
                    field: 'brower',
                    title: '浏览器'
                },
                {
                    field: 'content',
                    title: '请求内容',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(row.content,30,'open');
                    }
                },
                {
                    field: 'create_time',
                    title: '添加时间',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return $.common.timeToTime(row.create_time,2);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return edit_del(row);
                    }

                }]
        };
        $.table.init(options);
    });

    function edit_del(row) {
            var actions = [];
            actions.push('<a class="btn btn-danger btn-xs " data-original-title="删除" data-toggle="tooltip" onclick="$.form.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i></a>');
            return actions;
    }

    
    function del_all() {
        table.set();
        var url = table.options.deleteUrl;
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        ids=rows.join();
        if($.isArray(ids)) {
            ids = ids.join(',');
        }
        if ($.common.isEmpty(ids)) {
            $.models.toastr_error("没选择任何数据");return ;
        }
        var msgs="确认要删除选中的" + rows.length + "条数据吗?";
        layer.confirm(msgs,{ icon: 3, title: "提示", anim: 1}, function(index){
            layer.close(index);
            $.ajax({
                url: url,
                type: "POST",
                async: true,
                dataType: "json",
                data:{
                    ids: ids,
                    times:$("#time").val()
                },
                error: function(error) {
                    $.models.toastr_error("服务器错误或超时");
                    return false;
                },
                success: function(data) {
                    if (data.code==1) {
                        $.models.toastr_success(data.msg,function () {
                            setTimeout(function(){
                                $.table.refresh();
                            },800);
                        });
                    }else{
                        $.models.toastr_error(data.msg,function () {
                            setTimeout(function(){
                                $.table.refresh();
                            },800);
                        });
                    }
                },
                complete:function(){
                }
            });
        });
    }


</script>

{/block}
